package com.itheima.health.util;

import org.mindrot.jbcrypt.BCrypt;
import org.springframework.util.DigestUtils;

public class PasswordUtils {

    public static boolean checkPassword(String userPassword,String paramPassword) {
        if (userPassword.startsWith("{md5}")) {
            //加密方式MD5
            paramPassword = DigestUtils.md5DigestAsHex(paramPassword.getBytes());
            userPassword = userPassword.replace("{md5}", "");
            return paramPassword.equals(userPassword);
        } else if (userPassword.startsWith("{bcrypt}")) {
            //加密方式bcrypt
            userPassword = userPassword.replace("{bcrypt}", "");
            return BCrypt.checkpw(paramPassword, userPassword);
        }
        //未加密
        return paramPassword.equals(userPassword);
    }
}
